package com.ruoyi.bmxt.service.impl;

import java.util.List;

import com.ruoyi.common.constant.BmxtConstants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bmxt.mapper.BmSchoolLevelMapper;
import com.ruoyi.bmxt.domain.BmSchoolLevel;
import com.ruoyi.bmxt.service.IBmSchoolLevelService;

/**
 * 学校层次管理Service业务层处理
 * 
 * @author 魏建波
 * @date 2023-02-19
 */
@Service
public class BmSchoolLevelServiceImpl implements IBmSchoolLevelService 
{
    @Autowired
    private BmSchoolLevelMapper bmSchoolLevelMapper;

    /**
     * 查询学校层次管理
     * 
     * @param schoolLevelId 学校层次管理主键
     * @return 学校层次管理
     */
    @Override
    public BmSchoolLevel selectBmSchoolLevelBySchoolLevelId(Long schoolLevelId)
    {
        return bmSchoolLevelMapper.selectBmSchoolLevelBySchoolLevelId(schoolLevelId);
    }

    /**
     * 查询学校层次管理列表
     * 
     * @param bmSchoolLevel 学校层次管理
     * @return 学校层次管理
     */
    @Override
    public List<BmSchoolLevel> selectBmSchoolLevelList(BmSchoolLevel bmSchoolLevel)
    {
        return bmSchoolLevelMapper.selectBmSchoolLevelList(bmSchoolLevel);
    }

    /**
     * 新增学校层次管理
     * 
     * @param bmSchoolLevel 学校层次管理
     * @return 结果
     */
    @Override
    public int insertBmSchoolLevel(BmSchoolLevel bmSchoolLevel)
    {
        bmSchoolLevel.setCreateTime(DateUtils.getNowDate());
        return bmSchoolLevelMapper.insertBmSchoolLevel(bmSchoolLevel);
    }

    /**
     * 修改学校层次管理
     * 
     * @param bmSchoolLevel 学校层次管理
     * @return 结果
     */
    @Override
    public int updateBmSchoolLevel(BmSchoolLevel bmSchoolLevel)
    {
        bmSchoolLevel.setUpdateTime(DateUtils.getNowDate());
        return bmSchoolLevelMapper.updateBmSchoolLevel(bmSchoolLevel);
    }

    /**
     * 批量删除学校层次管理
     * 
     * @param schoolLevelIds 需要删除的学校层次管理主键
     * @return 结果
     */
    @Override
    public int deleteBmSchoolLevelBySchoolIds(Long[] schoolLevelIds)
    {
        return bmSchoolLevelMapper.deleteBmSchoolLevelBySchoolIds(schoolLevelIds);
    }

    /**
     * 删除学校层次管理信息
     * 
     * @param schoolId 学校层次管理主键
     * @return 结果
     */
    @Override
    public int deleteBmSchoolLevelBySchoolId(Long schoolId)
    {
        return bmSchoolLevelMapper.deleteBmSchoolLevelBySchoolLevelId(schoolId);
    }

    @Override
    public String checkSchoolLevelNameUnique(BmSchoolLevel bmSchoolLevel) {
        Long schoolLevelId = StringUtils.isNull(bmSchoolLevel.getSchoolLevelId()) ? -1L : bmSchoolLevel.getSchoolLevelId();
        BmSchoolLevel dbSchoolLevel = bmSchoolLevelMapper.checkSchoolLevelNameUnique(bmSchoolLevel);
        if (StringUtils.isNotNull(dbSchoolLevel) && dbSchoolLevel.getSchoolLevelId().longValue() != schoolLevelId.longValue())
        {
            return BmxtConstants.NOT_UNIQUE;
        }
        return BmxtConstants.UNIQUE;
    }
    /**
     * 查询所有学校层次列表
     * @return
     */
    @Override
    public List<BmSchoolLevel> selectAllBmSchoolLevelList() {
        return bmSchoolLevelMapper.selectAllBmSchoolLevelList();
    }
}
